//
// Created by hunan on 2025/10/1.
//

#ifndef OPEN_NET_HLS_DOWNLOAD_TASK_H
#define OPEN_NET_HLS_DOWNLOAD_TASK_H

#include <memory>
#include <string>

class ProtocolConnectionPool;
class ProtocolConnection;
class Loop;
class HlsFragment;
class HlsDownloadTask
{
public:
    HlsDownloadTask(const std::string & url, const std::string & m3u8_output, const std::string & fragment_output_path, int num);
    void StartDownload();
private:
    void StartDownloadFragment();
    void DownloadFragment();
    void ExecuteDownloadFragment(int index, const std::string & uri, const std::shared_ptr<ProtocolConnection>& connection);
    void Stop() const;
private:
    std::string m_url;
    std::string m_m3u8_output;
    std::string m_fragment_output_path;
    std::string m_fragment_full_path;
    int         m_connection_num = 10;
    Loop                                 *  m_loop;
    std::shared_ptr<ProtocolConnectionPool> m_hls_conn;
    std::shared_ptr<ProtocolConnectionPool> m_conn_pool;
    std::shared_ptr<HlsFragment>            m_hls_fragment;

};

#endif // OPEN_NET_HLS_DOWNLOAD_TASK_H
